home *** CD-ROM | disk | FTP | other *** search
/ Programming Windows 95 with MFC / Programming Windows 95 with MFC (Microsoft Programming Series)(097-0001465)(1996).iso / CODE / Chap08 / Paint4 / MainFrame.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-05  |  2.1 KB  |  79 lines

  1. //***********************************************************************
  2. //
  3. //  MainFrame.cpp
  4. //
  5. //***********************************************************************
  6.  
  7. #define OEMRESOURCE
  8.  
  9. #include <afxwin.h>
  10. #include "Resource.h"
  11. #include "CLine.h"
  12. #include "MainFrame.h"
  13. #include "Paint4Doc.h"
  14.  
  15. IMPLEMENT_DYNCREATE (CMainFrame, CFrameWnd)
  16.  
  17. BEGIN_MESSAGE_MAP (CMainFrame, CFrameWnd)
  18.     ON_WM_CREATE ()
  19.     ON_WM_MEASUREITEM ()
  20.     ON_WM_DRAWITEM ()
  21. END_MESSAGE_MAP ()
  22.  
  23. int CMainFrame::OnCreate (LPCREATESTRUCT lpcs)
  24. {
  25.     if (CFrameWnd::OnCreate (lpcs) == -1)
  26.         return -1;
  27.  
  28.     CMenu* pMenu = GetMenu ();
  29.     for (int i=0; i<8; i++)
  30.         pMenu->ModifyMenu (ID_COLOR_BLACK + i,
  31.             MF_BYCOMMAND | MF_OWNERDRAW, ID_COLOR_BLACK + i);
  32.     return 0;
  33. }
  34.  
  35. void CMainFrame::OnMeasureItem (int nIDCtl, LPMEASUREITEMSTRUCT lpmis)
  36. {
  37.     lpmis->itemWidth = ::GetSystemMetrics (SM_CYMENU) * 4;
  38.     lpmis->itemHeight = ::GetSystemMetrics (SM_CYMENU);
  39. }
  40.  
  41. void CMainFrame::OnDrawItem (int nIDCtl, LPDRAWITEMSTRUCT lpdis)
  42. {
  43.     BITMAP bm;
  44.     CBitmap bitmap;
  45.     bitmap.LoadOEMBitmap (OBM_CHECK);
  46.     bitmap.GetObject (sizeof (bm), &bm);
  47.  
  48.     CDC dc;
  49.     dc.Attach (lpdis->hDC);
  50.  
  51.     CBrush* pBrush = new CBrush (::GetSysColor ((lpdis->itemState &
  52.         ODS_SELECTED) ? COLOR_HIGHLIGHT : COLOR_MENU));
  53.     dc.FrameRect (&(lpdis->rcItem), pBrush);
  54.     delete pBrush;
  55.  
  56.     if (lpdis->itemState & ODS_CHECKED) {
  57.         CDC dcMem;
  58.         dcMem.CreateCompatibleDC (&dc);
  59.         CBitmap* pOldBitmap = dcMem.SelectObject (&bitmap);
  60.  
  61.         dc.BitBlt (lpdis->rcItem.left + 4, lpdis->rcItem.top +
  62.             (((lpdis->rcItem.bottom - lpdis->rcItem.top) -
  63.             bm.bmHeight) / 2), bm.bmWidth, bm.bmHeight, &dcMem,
  64.             0, 0, SRCCOPY);
  65.  
  66.         dcMem.SelectObject (pOldBitmap);
  67.     }
  68.  
  69.     pBrush = new CBrush (CPaintDoc::m_crColors[lpdis->itemID -
  70.         ID_COLOR_BLACK]);
  71.     CRect rect = lpdis->rcItem;
  72.     rect.DeflateRect (6, 4);
  73.     rect.left += bm.bmWidth;
  74.     dc.FillRect (rect, pBrush);
  75.     delete pBrush;
  76.  
  77.     dc.Detach ();
  78. }
  79.